home *** CD-ROM | disk | FTP | other *** search
Wrap
/* ** $VER: UUDecode.thor 4.1 (13.11.95) ** by Troels Walsted Hansen <troels@stud.cs.uit.no> ** ** Run CfgUUDecode.thor to configure this script. */ options results options failat 31 /* otherwise the output window may pop up all the time */ signal on break_c signal on halt signal on syntax /* Initialize some variables */ fromthor = 0; cmdlinemode = 0; cfgfile = ""; tmpdir = ""; destdir = ""; uudecoder= ""; uuprogpath = "" filenotes = 0; filerecog = 0; filetypecount = 0; progwin = 0; nocurrentmsg = 0; uudecoder.count = 0; firsttime = 0 /* Find THOR and BBSREAD ARexx ports' */ if(pos('THOR.', address()) > 0) then fromthor = 1 p=' '||address()||' '||show('P',,);if pos(' THOR.',p)>0 then thorport=word(substr(p,pos(' THOR.',p)+1),1);else do;say 'No THOR port found!';exit(0);end if ~show('p', 'BBSREAD') then do; address command; "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"; "WaitForPort BBSREAD"; end address(thorport) /* Get the path of the configuration file */ call open(pn, 'ENV:Thor/THORPATH', 'R') thorpath = readln(pn) call close(pn) if ~exists(thorpath'rexx') then cfgfile = 'ENV:Thor/UUDecode.cfg' else do if exists(thorpath'rexx/UUDecode.cfg') then cfgfile = thorpath'rexx/UUDecode.cfg' else cfgfile = 'ENV:Thor/UUDecode.cfg' end if ~exists(cfgfile) then do REQUESTNOTIFY '"Couldn''t find config file ('cfgfile').\nPlease run CfgUUDecode.thor and try again."' '"_Configure now|_Abort"' if(result) then address command 'run <>nil: rx ' || thorpath || 'Rexx/CfgUUDecode.thor' signal cleanup end /* Read configuration */ call readcfg /* If this is the first time the script is run, we ask the user to run the configscript */ if(firsttime) then do address(thorport) REQUESTNOTIFY TEXT '"It seems that you''re running this script for\nthe first time. It is very likely that you\nneed to change some of the defaults for this\nscript to work. Press Configure to configure\nthis script now, or Abort to quit the script."' BT '"_Configure|_Abort"' if(result) then address command 'run <>nil: rx ' || thorpath || 'Rexx/CfgUUDecode.thor' signal cleanup end /* General tmpfile */ tmpfile = tmpdir || 'doscommand.output' /* Disable filenoteadding if we got a filename on the commandline * and got started from somewhere other than THOR */ parse arg msgfilename if(msgfilename ~= '') then do cmdlinemode = 1 if(fromthor ~= 1) then filenotes = 0 end else msgfilename = tmpdir || 'Message.uu' if(~cmdlinemode) then do /* lock the gui till we're done */ address(thorport) LOCKGUI /* Need this info no matter what... */ CURRENTMSG stem MSG if(rc ~= 0) then do nocurrentmsg = 1 CURRENTSYSTEM stem MSG if(rc ~= 0) then do REQUESTNOTIFY TEXT '"CURRENTSYSTEM:\n'THOR.LASTERROR'"' BT '"_Abort"' signal cleanup end end /* find out whether multiple messages has been selected */ address(thorport) GETMSGLISTSELECTED stem SELECTED myrc = rc if(myrc = 0 & SELECTED.COUNT > 0 &Â nocurrentmsg ~= 1) then /* yes, there are multiple msgs, now query user */ do REQUESTNOTIFY TEXT '"UUDecode all files contained\nin all selected messages?"' BT '"_Yes|_Only current|_Abort"' if(result = 1) then nocurrentmsg = 1 else if(result = 2) then SELECTED.COUNT = 0 else signal cleanup end if((SELECTED.COUNT = 0 | (myrc > 1 & myrc < 6)) & MSG.MSGNR ~= "MSG.MSGNR") then /* save current msg only */ do SELECTED.COUNT = 1 SELECTED.1 = MSG.MSGNR /* Get the name or email address of the sender of this message */ if(filenotes) then do address(bbsread) READBRMESSAGE BBSNAME '"'MSG.BBSNAME'"' CONFNAME '"'MSG.CONFNAME'"' MSGNR MSG.MSGNR headstem HEADTAGS if(rc ~= 0) then do address(thorport) REQUESTNOTIFY TEXT '"READBRMESSAGE:\n'BBSREAD.LASTERROR'"' BT '"_Abort"' signal cleanup end if(HEADTAGS.FROMADDR ~= 'HEADTAGS.FROMADDR') then MSG.SENDER = HEADTAGS.FROMADDR else MSG.SENDER = HEADTAGS.FROMNAME end end if(myrc > 5 | SELECTED.COUNT = 0) then signal cleanup /* fatal error */ /* Open progressbar */ address(thorport) OPENPROGRESS TITLE '"UUDecoding message(s)..."' TOTAL SELECTED.COUNT AT "_Abort" PROGRESSCHARWIDTH 38 if rc = 0 then progwin = result else do REQUESTNOTIFY '"OPENPROGRESS:\n'THOR.LASTERROR'"' '"_Abort"' signal cleanup end /* Save msg(s) to disk with progressbar */ do i=1 to SELECTED.COUNT UPDATEPROGRESS REQ progwin CURRENT i PROGRESSTEXT '"' || 'Saving message ' || i ' of ' || SELECTED.COUNT || ' to disk...' || '"' if(rc ~= 0) then signal cleanup SAVEMESSAGE BBSNAME '"'MSG.BBSNAME'"' CONFNAME '"'MSG.CONFNAME'"' MSGNR SELECTED.i FILENAME msgfilename NOHEADER NOANSI if(rc ~= 0) then do REQUESTNOTIFY TEXT '"SAVEMESSAGE:\n'THOR.LASTERROR'"' BT '"_Abort' signal cleanup end end end else if ~exists(msgfilename) then do address(thorport) REQUESTNOTIFY TEXT '"Message containing uuencoded file not found."' BT '"_Ok"' signal cleanup end /* extract filenames if filenotes and/or filerecog is enabled */ if(filenotes | filerecog) then call FindFileNames /* uuDecode all files contained in the tempfile */ founduu = 0 do i=1 to uudecoder.count if(upper(uudecoder) = upper(uudecoder.i.shortname)) then do founduu = 1 cmd = uudecoder.i.commandline cmd = substitute(cmd, '%TmpFile', tmpfile) cmd = substitute(cmd, '%MsgFilename', msgfilename) cmd = substitute(cmd, '%DestDir', destdir) end end if(~founduu) then do address(thorport) REQUESTNOTIFY TEXT '"UUDecoder not configured correctly."' BT '"_Configure|_Abort"' if(result) then address command 'run <>nil: rx 'thorpath'Rexx/CfgUUDecode.thor' signal cleanup end if(~cmdlinemode) then do address(thorport) UPDATEPROGRESS REQ progwin PROGRESSTEXT '"UUDecoding file(s)..."' end address command cmd if(rc ~= 0) then do call open(tmpfh, tmpfile, R) errormsg = '' do until eof(tmpfh) errormsg = errormsg || '\n' || readln(tmpfh) end call close(tmpfh) errormsg = 'UUDecoding did not succeed.' || left(errormsg, length(errormsg)-2) address(thorport) REQUESTNOTIFY TEXT '"'errormsg'"' BT '"_Configure|_Abort"' if(result) then address command 'run <>nil: rx 'thorpath'Rexx/CfgUUDecode.thor' signal cleanup end /* Add filenotes if that option is switched on */ if(filenotes) then do if(~cmdlinemode) then do address(thorport) UPDATEPROGRESS REQ progwin PROGRESSTEXT '"Adding filenote(s)..."' end if(nocurrentmsg) then str = 'From ' || MSG.CONFNAME || ' on ' || MSG.BBSNAME else str = 'From ' || MSG.SENDER || ' in ' || MSG.CONFNAME || ' on ' || MSG.BBSNAME do i=1 to (filenamecount-1) address command 'filenote <>nil: ' || '"' || destdir || realfilename.i || '"' || ' ' || '"' || str || '"' || ' QUIET' end end /* Match fileextension against those configured by the user if filetyperecognition is switched on. */ if(filerecog) then do if(~cmdlinemode) then do address(thorport) UPDATEPROGRESS REQ progwin PROGRESSTEXT '"Doing filetype recognition..."' end address(thorport) GETGLOBALCONFIG stem THORCONFIG if(rc ~= 0) then do REQUESTNOTIFY TEXT '"GETGLOBALCONFIG:\n'THOR.LASTERROR'"' BT '"_Abort"' signal cleanup end do i=1 to (filenamecount-1) thisext = upper(substr(realfilename.i, lastpos(".", realfilename.i)+1)) do j=1 to filetypecount if(pos(thisext, filetype.j.ext) > 0 | upper(filetype.j.ext) = 'ALL') then do /* build a list of choices to present to the user */ choices = '' do k=1 to filetype.j.actioncount choices = choices || '|' || filetype.j.actionname.k end choices = substr(choices, 2) || '|_Skip this one' /* ask the user what to do */ address(thorport) REQUESTNOTIFY TEXT '"' || 'The file ' || realfilename.i || ' has been recognized as ' || filetype.j.name || '.\nWhich action would you like to perform on it?' || '"' BT '"'choices'"' action = result if(action ~= 0) then do /* substitute internal vars with actual meaning */ cmd = substitute(filetype.j.actioncmdl.action, '%FileName', destdir || realfilename.i) cmd = substitute(cmd, '%ThorScreen', THORCONFIG.PUBSCREENNAME) cmd = substitute(cmd, '%RequestDir') cmd = substitute(cmd, '%RequestFile') /* change the default output window to my very own */ call close 'STDOUT' call close 'STDIN' call open 'STDOUT','CON:0/16//400/UUDecode.thor/CLOSE/AUTO/WAIT/SCREEN' || THORCONFIG.PUBSCREENNAME call pragma '*','STDOUT' call open 'STDIN','*' /* launch the internal/external action */ command = upper(word(cmd, 1)) if(command = 'SHOWPICTURE' | command = 'SHOWTEXT') then do address(thorport) interpret cmd end else address command cmd if(rc ~= 0) then do address(thorport) REQUESTNOTIFY TEXT '"' || 'Failed to launch your configured\ncommandline for ' || filetype.j.actionname.action || '.' || '"' BT '"_Configure|_Ok"' if(result) then address command 'run <>nil: rx 'thorpath'Rexx/CfgUUDecode.thor' end end end end end end /* end of the script */ signal cleanup /* Some experimental error detection stuff */ error: syntax: say '+++Error 'rc' in line 'sigl': 'errortext(rc) say sourceline(sigl) if THOR.LASTERROR ~= 'THOR.LASTERROR' then say THOR.LASTERROR if BBSREAD.LASTERROR ~= 'BBSREAD.LASTERROR' then say BBSREAD.LASTERROR break_c: halt: cleanup: /* delete tmpfiles used */ if(exists(msgfilename) &Â ~cmdlinemode) then address command 'delete ' || msgfilename || ' quiet' if(exists(tmpfile)) then address command 'delete ' || tmpfile || ' quiet' /* Close progressbar if open */ if progwin ~= 0 then if progwin ~= 'PROGWIN' then do address(thorport) CLOSEPROGRESS REQ progwin progwin = 0 end UNLOCKGUI exit(0) /****************************************************************************** ********************************** PROCEDURES ********************************* ******************************************************************************/ /********************** Open and read configuration file *********************/ readcfg: procedure expose cfgfile tmpdir destdir uudecoder uuprogpath filenotes filerecog filetypecount filetype. progwin globalcfg. thorport uudecoder. firsttime call open(cf, cfgfile, 'R') do until eof(cf) subentry = "" entry = readln(cf) select when upper(entry) = "START" then do do until upper(subentry) = "END" subentry = readln(cf) select when upper(subword(subentry, 1, 1)) = 'TMPDIR:' then tmpdir = subword(subentry, 2) when upper(subword(subentry, 1, 1)) = 'DESTDIR:' then do destdir = subword(subentry, 2) if(upper(destdir) = "GLOBAL") then do address(bbsread) GETGLOBALDATA STEM GLOBALDATA if(rc ~= 0) then do address(thorport) REQUESTNOTIFY TEXT '"GETGLOBALDATA:\n'BBSREAD.LASTERROR'"' BT '"_Abort"' exit(20) end destdir = GLOBALDATA.DNLOADPATH endchar = right(destdir, 1) if(endchar ~= ":" & endchar ~= "/") then destdir = destdir || '/' end end when upper(subword(subentry, 1, 1)) = 'UUDECODER:' then uudecoder = subword(subentry, 2) when upper(subword(subentry, 1, 1)) = 'UUPROGPATH:' then uuprogpath = subword(subentry, 2) when upper(subword(subentry, 1, 1)) = 'FILENOTES:' then if upper(subword(subentry, 2, 1)) = 'YES' then filenotes = 1 when upper(subword(subentry, 1, 1)) = 'FILERECOG:' then if upper(subword(subentry, 2, 1)) = 'YES' then filerecog = 1 when upper(subword(subentry, 1, 1)) = 'FIRSTTIME:' then if upper(subword(subentry, 2, 1)) = 'YES' then firsttime = 1 otherwise nop end end end when upper(entry) = "FILETYPE" then do /* Read filetype configuration */ filetypecount = filetypecount + 1 actions = 0 do until upper(subentry) = "END" subentry = readln(cf) select when upper(subword(subentry, 1, 1)) = 'NAME:' then filetype.filetypecount.name = subword(subentry, 2) when upper(subword(subentry, 1, 1)) = 'EXTENSIONS:' then filetype.filetypecount.ext = upper(subword(subentry, 2)) when upper(subword(subentry, 1, 1)) = 'ACTIONNAME:' then do actions = actions + 1 filetype.filetypecount.actionname.actions = subword(subentry, 2) subentry = readln(cf) filetype.filetypecount.actioncmdl.actions = subword(subentry, 2) end otherwise nop end filetype.filetypecount.actioncount = actions end end when upper(entry) = "UUDECODER" then do uudecoder.count = uudecoder.count + 1 uudecoders = uudecoder.count do until upper(subentry) = "END" subentry = readln(cf) select when upper(subword(subentry, 1, 1)) = 'SHORTNAME:' then uudecoder.uudecoders.shortname = subword(subentry, 2) when upper(subword(subentry, 1, 1)) = 'LONGNAME:' then uudecoder.uudecoders.longname = subword(subentry, 2) when upper(subword(subentry, 1, 1)) = 'COMMANDLINE:' then uudecoder.uudecoders.commandline = subword(subentry, 2) otherwise nop end end end otherwise nop end end call close(cf) return /* Procedure that looks for 'begin xxx filename' lines, in order to extract filenames */ FindFileNames: procedure expose cmdlinemode tmpfile msgfilename thorport filenotes filenamecount realfilename. if(~cmdlinemode) then do address(thorport) UPDATEPROGRESS REQ progwin PROGRESSTEXT '"Searching for filenames..."' end address command "search >" || tmpfile || " " || msgfilename || " begin nonum" if(rc ~= 0) then do address(thorport) REQUESTNOTIFY TEXT '"Filenamesearch failed, filenote(s) won''t be added."' BT '"_Ok"' filenotes = 0 break end filenamecount = 1 call open(tmpfh, tmpfile, R) do until(eof(tmpfh)) str = readln(tmpfh) if(left(str, 5) = 'begin') then do realfilename.filenamecount = substr(str, wordindex(str, 3)) posi2 = 0 posi = pos(':', realfilename.filenamecount) if(posi ~= 0) then posi2 = posi posi = lastpos('/', realfilename.filenamecount) if(posi ~= 0) then posi2 = posi if(posi2 ~= 0) then realfilename.filenamecount = substr(realfilename.filenamecount, posi2+1) filenamecount = filenamecount+1 end end call close(tmpfh) RETURN /* Procedure for substituting strings inside another string with a string :-) */ Substitute: procedure expose thorport parse arg str, org, new found = index(str, org) do while found ~= 0 secondpart = substr(str, found+length(org)) firstpart = substr(str, 1, length(str) - length(substr(str, found))) if(org = '%RequestFile' | org = '%RequestDir') then do if(org = '%RequestFile') then pattern = '#?' else pattern = '~#?' address(thorport) REQUESTFILE TITLE '"Select destination:"' ID '"RAM:"' FP PAT '"'pattern'"' if(rc ~= 0) then new = "RAM:" else new = result end str = firstpart || new || secondpart found = index(str, org) end RETURN str